package com.itheima.tlias84.exception;

import com.itheima.tlias84.utils.ResultUtil;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 因为我们无法使用try-catch捕获进入controller 之前的异常
 * 但是可以使用aop对controller进行调用之前的增强
 * 因此@RestControllerAdvice相当于环绕通知controller
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(ArithmeticException.class)
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public ResultUtil handleArithmeticException(ArithmeticException exception){
        return ResultUtil.fail(exception);
    }
}
